package org.hzz.application.handler;

import io.gitee.pkmer.convention.converter.TargetAndSourceConverter;
import io.gitee.pkmer.convention.page.PageResponse;
import io.gitee.pkmer.designpattern.strategy.AbstractExecuteStrategy;
import lombok.Setter;
import org.hzz.application.command.UpdateCouponCmd;
import org.hzz.promotions.domain.entity.CouponEntity;
import org.hzz.promotions.domain.service.CouponDomainService;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author <a href="mailto:1193094618@qq.com">pkmer</a>
 * <br>
 * <a href = "https://gitee.com/developeros/videos-online">Code Repository</a>
 * At 2024/8/31
 */
@Component
public class UpdateCouponCmdHandler implements AbstractExecuteStrategy<UpdateCouponCmd,Void> {
    @Setter(onMethod_ = @Autowired)
    private CouponDomainService couponDomainService;
    @Override
    public String mark() {
        return UpdateCouponCmd.MARK;
    }

    @Override
    public void execute(UpdateCouponCmd cmd) {
        CouponEntity entity = Converter.INSTANCE.toTarget(cmd);
        couponDomainService.updateCouponEntity(entity);

    }

    @Mapper
    interface Converter extends TargetAndSourceConverter<CouponEntity,UpdateCouponCmd>{
        Converter INSTANCE = Mappers.getMapper(Converter.class);
    }
}
